#include <stdlib.h>
#include "layer.h"

void free_layer(layer l)
{
    if (l.weights) {
        free(l.weights);
        l.weights = NULL;
    }

    if (l.biases) {
        free(l.biases);
        l.biases = NULL;
    }

    if (l.output) {
        free(l.output);
        l.output = NULL;
    }

    if (l.delta) {
        free(l.delta);
        l.delta = NULL;
    }

    if (l.indexes) {
        free(l.indexes);
        l.indexes = NULL;
    }
}

void add_bias(float *output, float *biases, int batch, int n, int size)
{
    int i,j,b;
    for(b = 0; b < batch; ++b){
        for(i = 0; i < n; ++i){
            for(j = 0; j < size; ++j){
                output[(b*n + i)*size + j] += biases[i];
            }
        }
    }
}
